import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    VueSetupExtend(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        silenceDeprecations: ['legacy-js-api'],
        javascriptEnabled: true,
        additionalData: '@use "./src/styles/variable.scss" as *;',
      }
    }
  },
  server: {
    open: true,//启动项目自动弹出浏览器
    proxy: {
      '/admin': {
        target: 'http://localhost/admin/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/admin/, '') // 不可以省略rewrite
      }
    }
  }
})
